﻿#region License
// <copyright file="FactoryContext.cs" company="Kopigi - Marc Plessis">
// Copyright © Kopigi 2011
// </copyright>
// ****************************************************************************
// <author>Marc Plessis</author>
// <email>marc.plessis@kopigi.fr</email>
// <date>03/04/2011</date>
// <project>Biwo</project>
// <web>http://www.kopigi.fr/biwo</web>
// <license>
// See license.txt in this solution or http://www.microsoft.com/opensource/licenses.mspx
// </license>
#endregion

using System.Data.EntityClient;

namespace SQLServerCompactEdition.Repository.DAL.RepositoryDao
{
    public static class FactoryContext
    {
    	private static BiwoSampleContainer _context = null;
    	public static BiwoSampleContainer GetContext()
    	{
    		return _context;
    	}
    	
    	/// <summary>
        /// Set unique context to all RepositoryDao
        /// </summary>
        /// <param name="proxyAndLazyLoadingEnabled">Set ProxyCreationEnabled and LazyLoadingEnabled, default as true</param>
    	public static void SetContext(bool proxyAndLazyLoadingEnabled = false)
    	{
    		_context = new BiwoSampleContainer();
    		ClientDao.SetContext(_context, proxyAndLazyLoadingEnabled);
    		FournisseurDao.SetContext(_context, proxyAndLazyLoadingEnabled);
    		PersonneDao.SetContext(_context, proxyAndLazyLoadingEnabled);
    	}
    	
    	/// <summary>
        /// Set unique context to all RepositoryDao
        /// </summary>
        /// <param name="connectionString">ConnectionString Name</param>
        /// <param name="proxyAndLazyLoadingEnabled">Set ProxyCreationEnabled and LazyLoadingEnabled, default as true</param>
    	public static void SetContext(string connectionString, bool proxyAndLazyLoadingEnabled = false)
    	{
    		_context = new BiwoSampleContainer("name=" + connectionString);
    		ClientDao.SetContext(_context, proxyAndLazyLoadingEnabled);
    		FournisseurDao.SetContext(_context, proxyAndLazyLoadingEnabled);
    		PersonneDao.SetContext(_context, proxyAndLazyLoadingEnabled);
    	}
    	
    	/// <summary>
        /// Set unique context to all RepositoryDao
        /// </summary>
        /// <param name="connection">EntityConnection to context</param>
        /// <param name="proxyAndLazyLoadingEnabled">Set ProxyCreationEnabled and LazyLoadingEnabled, default as true</param>
    	public static void SetContext(EntityConnection connection, bool proxyAndLazyLoadingEnabled = false)
    	{
    		_context = new BiwoSampleContainer(connection);
    		ClientDao.SetContext(_context, proxyAndLazyLoadingEnabled);
    		FournisseurDao.SetContext(_context, proxyAndLazyLoadingEnabled);
    		PersonneDao.SetContext(_context, proxyAndLazyLoadingEnabled);
    	}
    }
}
